package com.enlorenz.support.jackson;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 日期数据转换
 * 将日期转为指定格式的字符串
 * @author Karma
 */
public class DateDataTransfer implements IDataTransfer{
	//日期模板
	private String datePattern;
	private SimpleDateFormat dateFormat;

	public String getDatePattern() {
		return datePattern;
	}

	public void setDatePattern(String datePattern) {
		this.datePattern = datePattern;
		dateFormat=new SimpleDateFormat(datePattern);
	}

	@Override
	public boolean isAdpat(Object data) {
		if(data instanceof Date){
			return true;
		}
		return false;
	}

	@Override
	public Object transfer(Object data) {
		Date date=(Date)data;
		return dateFormat.format(date);
	}
}
